//
//  CommanViewModel.swift
//  ezyform
//
//  Created by MoennigQ on 9/11/18.
//  Copyright © 2018 Client.Solution Pty Ltd. All rights reserved.
//

import UIKit
import DaisyNet
class CommanViewModel: BaseService {
    func checkAPPLatestVersion(closure: ((Any?, String?, String?)->Void)?){
        let request = DaisyNet.request(APIConfig.AppVersionAPI)
        request.responseData { resp in
            switch resp.result {
            case .success(let value ):
                do{
                    let asJSON = try JSONSerialization.jsonObject(with: value)
                    closure?(asJSON,nil,nil)
                }catch{
                    DebugLog("convert data to Json faild for (\(APIConfig.AppVersionAPI)")
                }
            case .failure(let error):
                let statusCode = resp.response?.statusCode ?? 0
                closure?(nil,"\(statusCode)",error.localizedDescription)
            }
        }
            
    }
    func checkAPPForceUpdateVersion(){
        
        let alRequest = ALRequest.init(mainURL: APIConfig.getRequestAPIForV2(APIConfig.AppForceUpdateAPI), method: .get, headers: RequestConstant.AuthLoginOtherParam, paramDict: nil, successBlock: { (obj, _) -> Void in
            self.returnBlock(obj, nil)
        }) {(code, obj) -> Void in
            self.errorBlock?(code, obj)
        }
        alRequest.startRequest()
    }
    func getScanOfflineLicense(){
        
        let alRequest = ALRequest.init(mainURL: APIConfig.getRequestAPIForV2(APIConfig.ScanOfflieLicenseAPI), method: .get, headers: RequestConstant.AuthLoginOtherParam, paramDict: nil, successBlock: { (obj, _) -> Void in
            self.returnBlock(obj, nil)
        }) {(code, obj) -> Void in
            self.errorBlock?(code, obj)
        }
        alRequest.startRequest()
    }
}
